//
//  XMQHttpTransfer.h
//  XiaoMiQuan
//
//  Created by liaowei on 14-4-18.
//
//

#import <Foundation/Foundation.h>


@protocol XMQHttpFileTransferDelegate;

@interface XMQHttpTransfer : NSOperation<NSURLConnectionDataDelegate>

@end


@interface XMQFileTansferRequest : NSObject

@property (assign, nonatomic) id<XMQHttpFileTransferDelegate> delegate;

- (id)initWithOperationCount:(NSInteger)count;

- (void)addAsyncRequest:(NSNumber *)requestId
                userObj:(id)userObj
                 method:(NSString *)method
                    url:(NSString *)url
               withBody:(NSData *)body
      waitUntilFinished:(BOOL)waitUntilFinished
                  error:(NSError **)error;

- (void)addAsyncRequest:(NSNumber *)requestId
                userObj:(id)userObj
                 method:(NSString *)method
                    url:(NSString *)url
         withBodyFile:(NSString *)bodyFile
      waitUntilFinished:(BOOL)waitUntilFinished
                  error:(NSError **)error;

- (void)addAsyncRequest:(NSNumber *)requestId
                userObj:(id)userObj
                 method:(NSString *)method
                    url:(NSString *)url
           withBodyFile:(NSString *)bodyFile
           responseFile:(NSString *)responseFile
      waitUntilFinished:(BOOL)waitUntilFinished
                  error:(NSError **)error;

- (void)addAsyncRequest:(NSNumber *)requestId
                userObj:(id)userObj
                 method:(NSString *)method
                    url:(NSString *)url
               withBody:(NSData *)body
           responseFile:(NSString *)responseFile
      waitUntilFinished:(BOOL)waitUntilFinished
                  error:(NSError **)error;

// 返回当前队列数量
- (NSUInteger)currentOperationCount;

- (void)cancelAllOperations;

@end    // interface XMQFileTansferRequest


@protocol XMQHttpFileTransferDelegate <NSObject>

- (void)httpFileTransfer:(NSNumber *)requestId
                 userObj:(id)userObj didFailWithError:(NSError *)error;

- (void)httpFileTransfer:(NSNumber *)requestId userObj:(id)userObj
         didSendBodyData:(NSInteger)bytesWritten
       totalBytesWritten:(NSInteger)totalBytesWritten
totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite;

- (void)httpFileTransfer:(NSNumber *)requestId
                 userObj:(id)userObj didReceiveResponse:(NSURLResponse *)response;

- (void)httpFileTransfer:(NSNumber *)requestId
                 userObj:(id)userObj didReceiveData:(NSData *)data;

- (void)httpFileTransferDidFinishLoading:(NSNumber *)requestId userObj:(id)userObj;

@end    // protocol XMQHttpFileTransferDelegate
